package com.briup.appointment.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.briup.appointment.common.ApiResponse;
import com.briup.appointment.domain.CsMessage;
import com.briup.appointment.domain.CsTicket;
import com.briup.appointment.service.CsMessageService;
import com.briup.appointment.service.CsTicketService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cs")
public class CustomerSupportController {

    private final CsTicketService ticketService;
    private final CsMessageService messageService;

    public CustomerSupportController(CsTicketService ticketService, CsMessageService messageService) {
        this.ticketService = ticketService;
        this.messageService = messageService;
    }

    @PostMapping("/ticket/create")
    public ApiResponse<Void> create(@RequestBody CsTicket ticket) {
        ticketService.save(ticket);
        return ApiResponse.ok();
    }

    @GetMapping("/ticket/my")
    public ApiResponse<List<CsTicket>> my(@RequestParam Long userId) {
        return ApiResponse.ok(ticketService.list(new LambdaQueryWrapper<CsTicket>().eq(CsTicket::getUserId, userId)));
    }

    @PostMapping("/message/send")
    public ApiResponse<Void> send(@RequestBody CsMessage msg) {
        messageService.save(msg);
        return ApiResponse.ok();
    }

    @GetMapping("/message/list")
    public ApiResponse<List<CsMessage>> list(@RequestParam Long ticketId) {
        return ApiResponse.ok(messageService.list(new LambdaQueryWrapper<CsMessage>().eq(CsMessage::getTicketId, ticketId)));
    }
}


